import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation

import matplotlib.image as mpimg

main_image = mpimg.imread('/home/lsr/project/CPP-CS106L/Assignment/Assignment_7/resources/image.jpg')
thumbnail_image = mpimg.imread('/home/lsr/project/CPP-CS106L/Assignment/Assignment_7/resources/image_copy.jpg')

# 设置绘图参数
fig, ax = plt.subplots()
ax.imshow(main_image)

x = np.linspace(0, 2*np.pi, 200)
line, = ax.plot(x, 2* np.sin(10*x))  # 初始正弦曲线
ax.set_xlim(0, 2*np.pi)        # 固定x轴范围
ax.set_ylim(-1.5, 1.5)         # 固定y轴范围


ax.imshow(thumbnail_image, extent=[0.7, 1.0, 0.5, 1.0], alpha=0.8) 

# 初始化函数，设定背景
def init():
    line.set_ydata([np.nan] * len(x))  # 清空曲线
    return line,

# 更新函数，每一帧调整相位
def update(frame):
    phase = 0.1 * frame             # 相位随帧数变化
    line.set_ydata(0.15 * np.sin( 10 * x + phase) - 0.5)  # 更新y值
    line.set_color( color= 'black')
    return line,

# 创建动画，间隔50毫秒，总帧数200
ani = FuncAnimation(
    fig, update, init_func=init,
    frames=200, interval=50, blit=True
)

ax.axis('off')

plt.show()